package com.xinbochuang.machine.admin.controller.api;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.xinbochuang.machine.admin.domain.*;
import com.xinbochuang.machine.admin.domain.macRoom.*;
import com.xinbochuang.machine.admin.domain.plan.CheckPlan;
import com.xinbochuang.machine.admin.domain.system.SysUser;
import com.xinbochuang.machine.admin.dto.AesRequestBean;
import com.xinbochuang.machine.admin.dto.EquipmentDetailDto;
import com.xinbochuang.machine.admin.dto.MacInOutDto;
import com.xinbochuang.machine.admin.mapper.PowerOrderMapper;
import com.xinbochuang.machine.admin.mapper.PowerOrderRackMapper;
import com.xinbochuang.machine.admin.mapper.PowerOrderRoomMapper;
import com.xinbochuang.machine.admin.mapper.macRoom.*;
import com.xinbochuang.machine.admin.service.*;
import com.xinbochuang.machine.admin.service.macRoom.IEquCabinetService;
import com.xinbochuang.machine.admin.service.macRoom.IMacRoomService;
import com.xinbochuang.machine.admin.service.macRoom.IMacShowService;
import com.xinbochuang.machine.admin.service.macRoom.IUlocationService;
import com.xinbochuang.machine.admin.service.plan.ICheckPlanService;
import com.xinbochuang.machine.admin.service.system.ISysUserService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.common.domain.LoginUser;
import com.xinbochuang.machine.common.domain.TableDataInfo;
import com.xinbochuang.machine.common.utils.AESUtils;
import com.xinbochuang.machine.common.utils.HttpUtils;
import com.xinbochuang.machine.common.utils.ServletUtils;
import com.xinbochuang.machine.common.utils.StringUtils;
import com.xinbochuang.machine.framework.web.domain.AjaxResult;
import com.xinbochuang.machine.framework.web.service.SysLoginService;
import com.xinbochuang.machine.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * app用户接口
 *
 * @author 黄晓鹏
 * @date 2020-09-25 15:51
 */
@Api(value = "app通用接口", position = 100, protocols = "http")
@RestController
@Validated
@RequestMapping("/api/app/")
public class AppApiController extends BaseController {

    @Autowired
    ICertificationService certificationService;

    @Resource
    private SysLoginService loginService;

    @Autowired
    private IMacinoutService iMacinoutService;

    @Autowired
    private IGejieOrderService gejieOrderService;

    @Autowired
    private IShigongOrderService shigongOrderService;

    @Autowired
    private IMacRoomService macRoomService;

    @Autowired
    private IMacinoutAcceptResultService macinoutAcceptResultService;

    @Autowired
    private IMacinoutAssociationService macinoutAssociationService;


    @Autowired
    private IEquCabinetService iEquCabinetService;
    @Autowired
    private IMacRoomResourceConfigService iMacRoomResourceConfigService;
    @Autowired
    private IMacRoomResourceService iMacRoomResourceService;

    @Autowired
    private IMacRoomResourceViewService iMacRoomResourceViewService;

    @Autowired
    private IUlocationService iUlocationService;

    @Autowired
    private IStorageRackService iStorageRackService;


    @Autowired
    private IMacShowService iMacShowService;

    @Autowired
    private ISysUserService iSysUserService;


    @Autowired
    IMacCheckRecordService iMacCheckRecordService;

    @Resource
    private TokenService tokenService;

    @Resource
    private ICheckPlanService checkPlanService;

    @Autowired
    EquipmentMapper equipmentMapper;

    @Autowired
    EquipmentDetailMapper equipmentDetailMapper;

    @Autowired
    MacBuildMapper macBuildMapper;

    @Autowired
    MacIndustrialMapper macIndustrialMapper;

    @Autowired
    PowerOrderRoomMapper powerOrderRoomMapper;

    @Autowired
    PowerOrderMapper powerOrderMapper;

    @Autowired
    PowerOrderRackMapper powerOrderRackMapper;
    /**
     * 新增资质
     * @param data
     * @return
     */
    /**
     * app添加用户
     *
     * @return 结果
     */
    @PostMapping("/insertCertification")
    public AjaxResult insertCertification(@RequestParam("data")String data, @RequestParam("file")MultipartFile file){
        Certification certification= JSONUtil.toBean(data,Certification.class);
        try {
            String fileName = certificationService.uploadFile(file);
            certification.setImgUrl(fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return toAjax(certificationService.insertCertification(certification));
    }

    @PostMapping("/insertCertificationN")
    public AjaxResult insertCertificationN(@RequestParam("data")String data, @RequestParam("file")MultipartFile file){
        Certification certification= JSONUtil.toBean(AESUtils.decode(data),Certification.class);
        try {
            String fileName = certificationService.uploadFile(file);
            certification.setImgUrl(fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return toAjax(certificationService.insertCertification(certification));
    }

    /**
     * 根据机房进出管理单名称分页获取列表
     * @param Macinout
     * @return
     */
    @GetMapping("/macinout/list")
    public TableDataInfo getMacInoutList(Macinout Macinout){
        return  getDataTable(iMacinoutService.findMacRoomByNameForPageApp(Macinout));
    }


    /**
     * 根据机房进出管理单名称分页获取列表
     * @param Macinout
     * @return
     */
    @GetMapping("/macinout/listN")
    public AjaxResult getMacInoutListN(Macinout Macinout){
        return  AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(iMacinoutService.findMacRoomByNameForPageApp(Macinout)),"yyyy-MM-dd HH:mm:ss")));
    }

    @GetMapping("/macinout/getAllGejieOrder")
    public AjaxResult getAllGejieOrder(){
        QueryWrapper<GejieOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(GejieOrder::getDeleteFlag, 0);
        queryWrapper.lambda().ge(GejieOrder::getGjWorkEndTime, DateUtil.today());
        queryWrapper.notInSql("uuid","select order_id from macinout where order_id is not null group by order_id");
        //queryWrapper.lambda().like(GejieOrder::getGjMacName,"银川市金凤区生产中心2号楼");
        queryWrapper.orderByAsc("gj_work_begin_time");
        return AjaxResult.data(gejieOrderService.list(queryWrapper));
    }
    @GetMapping("/macinout/getAllGejieOrderN")
    public AjaxResult getAllGejieOrderN(){
        QueryWrapper<GejieOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(GejieOrder::getDeleteFlag, 0);
        queryWrapper.lambda().ge(GejieOrder::getGjWorkEndTime, DateUtil.today());
        queryWrapper.notInSql("uuid","select order_id from macinout where order_id is not null group by order_id");
        //queryWrapper.lambda().like(GejieOrder::getGjMacName,"银川市金凤区生产中心2号楼");
        queryWrapper.orderByAsc("gj_work_begin_time");
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(gejieOrderService.list(queryWrapper),"yyyy-MM-dd HH:mm:ss")));
    }


    @GetMapping("/macinout/getAllShiGongOrder")
    public AjaxResult getAllShiGongOrder(){
        QueryWrapper<ShigongOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ShigongOrder::getDeleteFlag, 0);
        queryWrapper.lambda().ge(ShigongOrder::getSgWorkEndTime, DateUtil.today());
        queryWrapper.notInSql("uuid","select order_id from macinout where order_id is not null group by order_id");
        queryWrapper.lambda().like(ShigongOrder::getSgMacName,"银川市金凤区生产中心2号楼");
        queryWrapper.orderByAsc("sg_work_begin_time");
        return AjaxResult.data(shigongOrderService.list(queryWrapper));
    }

    @GetMapping("/macinout/getAllShiGongOrderN")
    public AjaxResult getAllShiGongOrderN(){
        QueryWrapper<ShigongOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ShigongOrder::getDeleteFlag, 0);
        queryWrapper.lambda().ge(ShigongOrder::getSgWorkEndTime, DateUtil.today());
        queryWrapper.notInSql("uuid","select order_id from macinout where order_id is not null group by order_id");
//        queryWrapper.lambda().like(ShigongOrder::getSgMacName,"银川市金凤区生产中心2号楼");
        queryWrapper.orderByAsc("sg_work_begin_time");
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(shigongOrderService.list(queryWrapper),"yyyy-MM-dd HH:mm:ss")));
    }
    /**
     * 获取全部自有人员
     */
    @GetMapping("/getOwnnerByDeptId")
    public AjaxResult getOwnner(@RequestParam ("deptId") String deptId){
        return AjaxResult.data(iMacinoutService.getOwnner(deptId));
    }

    /**
     * 获取全部自有人员
     */
    @GetMapping("/getOwnnerByDeptIdN")
    public AjaxResult getOwnnerN(@RequestParam ("deptId") String deptId){
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(iMacinoutService.getOwnner(deptId),"yyyy-MM-dd HH:mm:ss")));
    }

    /**getWaitAcceptList
     * 获取全部自有人员
     */
    @GetMapping("/getUserByDeptId")
    public AjaxResult getUserByDeptId(@RequestParam ("deptId") String deptId){
        return AjaxResult.data(iMacinoutService.getWorker(deptId));
    }

    /**getWaitAcceptList
     * 获取全部自有人员
     */
    @GetMapping("/getUserByDeptIdN")
    public AjaxResult getUserByDeptIdN(@RequestParam ("deptId") String deptId){
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(iMacinoutService.getWorker(deptId),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 施工机房远程搜索
     */
    @GetMapping("/selectMacRoom")
    public TableDataInfo selectMacRoom(@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("macName") String macName){

        MacRoom macRoom=new MacRoom();
        macRoom.setPageSize(pageSize);
        macRoom.setPageNum(pageNum);
        macRoom.setMacName(macName);
        LambdaQueryWrapper<MacRoom> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(MacRoom::getMacName,macName).eq(MacRoom::getDelteFlag,"0");
//        IPage<MacRoom> macRoomByNameForPage = macRoomService.findMacRoomByNameForPage(macRoom);
        return getDataTable(macRoomService.page(new Page<>(macRoom.getPageNum(),macRoom.getPageSize()),lambdaQueryWrapper));
    }

    /**
     * 施工机房远程搜索
     */
    @GetMapping("/selectMacRoomN")
    public AjaxResult selectMacRoomN(@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("macName") String macName){

        MacRoom macRoom=new MacRoom();
        macRoom.setPageSize(pageSize);
        macRoom.setPageNum(pageNum);
        macRoom.setMacName(macName);
        LambdaQueryWrapper<MacRoom> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(MacRoom::getMacName,macName).eq(MacRoom::getDelteFlag,"0");
//        IPage<MacRoom> macRoomByNameForPage = macRoomService.findMacRoomByNameForPage(macRoom);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(macRoomService.page(new Page<>(macRoom.getPageNum(),macRoom.getPageSize()),lambdaQueryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 新增机房出入单
     * @param macInOutDto
     * @return
     */
    @PostMapping("/insertMacinout")
    public AjaxResult insertMacinout(@RequestBody MacInOutDto macInOutDto){
        String name = iSysUserService.getById(macInOutDto.getLoginUserId()).getNickname();
        macInOutDto.setCreateBy(name);
        macInOutDto.setCreateTime(DateUtil.now());
        return toAjax(iMacinoutService.insertMacinout(macInOutDto));
    }

    /**
     * 新增机房出入单
     * @return
     */
    @PostMapping("/insertMacinoutN")
    public AjaxResult insertMacinoutN(@RequestBody AesRequestBean aesRequestBean){
        String decode = AESUtils.decode(aesRequestBean.getData());
        MacInOutDto macInOutDto=JSON.parseObject(decode,MacInOutDto.class);
        String name = iSysUserService.getById(macInOutDto.getLoginUserId()).getNickname();
        macInOutDto.setCreateBy(name);
        macInOutDto.setCreateTime(DateUtil.now());
        return toAjax(iMacinoutService.insertMacinout(macInOutDto));
    }
    /**
     * 修改机房出入单
     *
     * @param macInOutDto
     * @return
     */
    @PostMapping("/updateMacinout")
    public AjaxResult updateMacinout(@RequestBody MacInOutDto macInOutDto) {
        return toAjax(iMacinoutService.updateMacinout(macInOutDto));
    }

    /**
     * 修改机房出入单
     *
     * @return
     */
    @PostMapping("/updateMacinoutN")
    public AjaxResult updateMacinoutN(@RequestBody AesRequestBean aesRequestBean) {
        String decode = AESUtils.decode(aesRequestBean.getData());
        MacInOutDto macInOutDto=JSON.parseObject(decode,MacInOutDto.class);
        return toAjax(iMacinoutService.updateMacinout(macInOutDto));
    }
    /**
     * 根据UUID查询机房出入单详情
     * @param uuid
     * @return
     */
    @GetMapping("/macinout/getOrderDetail")
    public AjaxResult getMacinoutById(@RequestParam("id") String uuid){
        AjaxResult ajax = AjaxResult.ok();
        if (StringUtils.isNotNull(uuid)) {
            MacInOutDto macInOutDto = iMacinoutService.getMacinoutById(uuid);
            macInOutDto.setWorker(iMacinoutService.getWorkerList(uuid));
            macInOutDto.setMacList(iMacinoutService.getMacList(uuid));
            ajax.put(AjaxResult.DATA_TAG, macInOutDto);
        }
        return ajax;
    }
    /**
     * 根据UUID查询机房出入单详情
     * @param uuid
     * @return
     */
    @GetMapping("/macinout/getOrderDetailN")
    public AjaxResult getMacinoutByIdN(@RequestParam("id") String uuid){
        AjaxResult ajax = AjaxResult.ok();
        if (StringUtils.isNotNull(uuid)) {
            MacInOutDto macInOutDto = iMacinoutService.getMacinoutById(uuid);
            macInOutDto.setWorker(iMacinoutService.getWorkerList(uuid));
            macInOutDto.setMacList(iMacinoutService.getMacList(uuid));
            ajax.put(AjaxResult.DATA_TAG, AESUtils.encode(JSON.toJSONStringWithDateFormat(macInOutDto,"yyyy-MM-dd HH:mm:ss")));
        }
        return ajax;
    }
    @GetMapping("/macinout/getGjOrderDataDetail")
    public AjaxResult getGjOrderDataDetail(@RequestParam("id") String uuid){
        return AjaxResult.data(gejieOrderService.getById(uuid));
    }
    @GetMapping("/macinout/getGjOrderDataDetailN")
    public AjaxResult getGjOrderDataDetailN(@RequestParam("id") String uuid){
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(gejieOrderService.getById(uuid),"yyyy-MM-dd HH:mm:ss")));
    }

    @GetMapping("/macinout/getSGOrderDataDetail")
    public AjaxResult getSGOrderDataDetail(@RequestParam("id") String uuid){
        return AjaxResult.data(shigongOrderService.getById(uuid));
    }
    /**
     * 修改机房出入单checklist
     * @param macInOutDto
     * @return
     */
    @PostMapping("/macinout/approve")
    public AjaxResult approveMacinout(@RequestBody Macinout macInOutDto){

        return toAjax(iMacinoutService.approveMacinoutByApp(macInOutDto));
    }
    /**
     * 修改机房出入单checklist
     * @return
     */
    @PostMapping("/macinout/approveN")
    public AjaxResult approveMacinoutN(@RequestBody AesRequestBean aesRequestBean){
        String decode = AESUtils.decode(aesRequestBean.getData());
        Macinout macInOutDto=JSON.parseObject(decode,Macinout.class);
        return toAjax(iMacinoutService.approveMacinoutByApp(macInOutDto));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(审核)
     * @param macinout
     * @return
     */
    @GetMapping("/macinout/checklist")
    public TableDataInfo getCheckMacInoutList(Macinout macinout){
        int pageNum = macinout.getPageNum();
        macinout.setPageNum(pageNum-1);
        return getDataTable(iMacinoutService.getCheckMacInoutList(macinout));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(审核)
     * @param macinout
     * @return
     */
    @GetMapping("/macinout/checklistN")
    public AjaxResult getCheckMacInoutListN(Macinout macinout){
        int pageNum = macinout.getPageNum();
        macinout.setPageNum(pageNum-1);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(iMacinoutService.getCheckMacInoutList(macinout)),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(验收列表)
     * @return
     */
    @GetMapping("/macinout/getWaitAcceptList")
    public TableDataInfo getWaitAcceptList(@RequestParam("userId")String userid,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("queryOrderStatus")String queryOrderStatus){
//        String queryOrderStatus ="4";
        return getDataTable(iMacinoutService.getWaitAcceptList(queryOrderStatus,userid,pageNum,pageSize));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(验收列表)
     * @return
     */
    @GetMapping("/macinout/getWaitAcceptListN")
    public AjaxResult getWaitAcceptListN(@RequestParam("userId")String userid,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("queryOrderStatus")String queryOrderStatus){
//        String queryOrderStatus ="4";
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(iMacinoutService.getWaitAcceptList(queryOrderStatus,userid,pageNum,pageSize)),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 机房申请验收
     * @return
     */
    @PostMapping("/macinout/accept")
    public AjaxResult acceptMacinout(@RequestBody MacinoutAcceptResult acceptResult){
        //保存验收结果
        acceptResult.setUuid(UUID.randomUUID().toString());
        acceptResult.setCreateTime(DateUtil.now());
        macinoutAcceptResultService.save(acceptResult);
        //根据assid更新对应工单中某一机房验收状态
        UpdateWrapper<MacinoutAssociation> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("order_status",5);
        updateWrapper.eq("uuid",acceptResult.getMacinoutAssId());
        macinoutAssociationService.update(updateWrapper);

        //根据assid查询MacinoutAssociation 中工单ID,查看这一工单下的机房是否都验收
        MacinoutAssociation byId = macinoutAssociationService.getById(acceptResult.getMacinoutAssId());
        List<MacinoutAssociation> macListN = macinoutAssociationService.list(new QueryWrapper<MacinoutAssociation>()
                .lambda().eq(MacinoutAssociation::getMacinoutId,byId.getMacinoutId())
                .eq(MacinoutAssociation::getDeleteFlag, 0).notIn(MacinoutAssociation::getOrderStatus,"5"));
        //如果为空则说明机房都已验收，则工单状态更新为验收
        if (macListN.isEmpty()) {
            UpdateWrapper<Macinout> updateWrapper1=new UpdateWrapper<>();
            Macinout macinout = iMacinoutService.getById(byId.getMacinoutId());
            String name = iSysUserService.getById(acceptResult.getLoginUserId()).getNickname();
            String now = DateUtil.now();
            updateWrapper1.lambda().set(Macinout::getOrderStatus,"5").set(Macinout::getConfirmByUser,name).set(Macinout::getConfirmTime,now).eq(Macinout::getUuid,byId.getMacinoutId());
            iMacinoutService.update(updateWrapper1);
            //记录工单审核状态
            iMacCheckRecordService.insertCheckRecord(acceptResult.getLoginUserId(),"5",byId.getMacinoutId());
        }
        return AjaxResult.ok();
    }


    /**
     * 机房申请验收
     * @return
     */
    @PostMapping("/macinout/acceptN")
    public AjaxResult acceptMacinoutN(@RequestBody AesRequestBean aesRequestBean){
        String decode = AESUtils.decode(aesRequestBean.getData());
        MacinoutAcceptResult acceptResult=JSON.parseObject(decode,MacinoutAcceptResult.class);
        //保存验收结果
        acceptResult.setUuid(UUID.randomUUID().toString());
        acceptResult.setCreateTime(DateUtil.now());
        macinoutAcceptResultService.save(acceptResult);
        //根据assid更新对应工单中某一机房验收状态
        UpdateWrapper<MacinoutAssociation> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("order_status",5);
        updateWrapper.eq("uuid",acceptResult.getMacinoutAssId());
        macinoutAssociationService.update(updateWrapper);

        //根据assid查询MacinoutAssociation 中工单ID,查看这一工单下的机房是否都验收
        MacinoutAssociation byId = macinoutAssociationService.getById(acceptResult.getMacinoutAssId());
        List<MacinoutAssociation> macListN = macinoutAssociationService.list(new QueryWrapper<MacinoutAssociation>()
                .lambda().eq(MacinoutAssociation::getMacinoutId,byId.getMacinoutId())
                .eq(MacinoutAssociation::getDeleteFlag, 0).notIn(MacinoutAssociation::getOrderStatus,"5"));
        //如果为空则说明机房都已验收，则工单状态更新为验收
        if (macListN.isEmpty()) {
            UpdateWrapper<Macinout> updateWrapper1=new UpdateWrapper<>();
            Macinout macinout = iMacinoutService.getById(byId.getMacinoutId());
            String name = iSysUserService.getById(acceptResult.getLoginUserId()).getNickname();
            String now = DateUtil.now();
            updateWrapper1.lambda().set(Macinout::getOrderStatus,"5").set(Macinout::getConfirmByUser,name).set(Macinout::getConfirmTime,now).eq(Macinout::getUuid,byId.getMacinoutId());
            iMacinoutService.update(updateWrapper1);
            //记录工单审核状态
            iMacCheckRecordService.insertCheckRecord(acceptResult.getLoginUserId(),"5",byId.getMacinoutId());
        }
        return AjaxResult.ok();
    }

    /**
     * 机房申请验收
     * @return
     */
    @GetMapping("/macinout/getAcceptById")
    public AjaxResult getAcceptById(@RequestParam("id")String id){
        //保存验收结果
        LambdaQueryWrapper<MacinoutAcceptResult> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MacinoutAcceptResult::getMacinoutAssId,id);
        List<MacinoutAcceptResult> macinoutAcceptResult = macinoutAcceptResultService.list(lambdaQueryWrapper);
        return AjaxResult.data(macinoutAcceptResult);
    }

    /**
     * 机房申请验收
     * @return
     */
    @GetMapping("/macinout/getAcceptByIdN")
    public AjaxResult getAcceptByIdN(@RequestParam("id")String id){
        //保存验收结果
        LambdaQueryWrapper<MacinoutAcceptResult> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MacinoutAcceptResult::getMacinoutAssId,id);
        List<MacinoutAcceptResult> macinoutAcceptResult = macinoutAcceptResultService.list(lambdaQueryWrapper);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(macinoutAcceptResult,"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(审核)
     * @return
     */
    @GetMapping("/macroom/findEquCabinetNodeByMacId")
    public AjaxResult findEquCabinetNodeByMacId(@RequestParam("macId")String macId){
        return AjaxResult.data(iEquCabinetService.findEquCabinetNodeByMacId(macId));
    }

    /**
     * 根据机房进出管理单名称分页获取列表(审核)
     * @return
     */
    @GetMapping("/macroom/findEquCabinetNodeByMacIdN")
    public AjaxResult findEquCabinetNodeByMacIdN(@RequestParam("macId")String macId){
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(iEquCabinetService.findEquCabinetNodeByMacId(macId),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 根据机房名称查询机房信息
     * @param macRoom
     * @return
     */
    @GetMapping("/macroom/getMacRoomList")
    public TableDataInfo getMacRoomList(MacRoom macRoom){
        QueryWrapper<MacRoom> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(macRoom.getDeptId()+"")){
            queryWrapper.lambda().eq(MacRoom::getDeptId,macRoom.getDeptId());
        }
        return getDataTable(macRoomService.page(new Page<>(macRoom.getPageNum(),macRoom.getPageSize()),queryWrapper));
    }

    /**
     * 根据机房名称查询机房信息
     * @param macRoom
     * @return
     */
    @GetMapping("/macroom/getMacRoomListN")
    public AjaxResult getMacRoomListN(MacRoom macRoom){
        QueryWrapper<MacRoom> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MacRoom::getDelteFlag,0);
        if(macRoom.getDeptId()!= null){
            queryWrapper.lambda().eq(MacRoom::getDeptId,macRoom.getDeptId());
        }
        if(macRoom.getBuildId()!=null){
            queryWrapper.lambda().eq(MacRoom::getBuildId,macRoom.getBuildId());
        }
        if(StringUtils.isNotBlank(macRoom.getMacName())){
            queryWrapper.lambda().like(MacRoom::getMacName,macRoom.getMacName());
        }
        queryWrapper.lambda().orderByAsc(MacRoom::getMacName);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(macRoomService.page(new Page<>(macRoom.getPageNum(),macRoom.getPageSize()),queryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }


    /**
     * 根据机房名称查询机房信息
     * @param resourceType
     * @return
     */
    @GetMapping("/macroom/getResourceConfig")
    public AjaxResult getResourceConfig(@RequestParam("resourceType")String resourceType){
        QueryWrapper<MacRoomResourceConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MacRoomResourceConfig::getResourceType,resourceType).orderByDesc(MacRoomResourceConfig::getSort);
        return AjaxResult.data(iMacRoomResourceConfigService.list(queryWrapper));
    }

    /**
     * 根据机房名称查询机房信息
     * @param resourceType
     * @return
     */
    @GetMapping("/macroom/getResourceConfigN")
    public AjaxResult getResourceConfigN(@RequestParam("resourceType")String resourceType){
        QueryWrapper<MacRoomResourceConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MacRoomResourceConfig::getResourceType,resourceType).orderByDesc(MacRoomResourceConfig::getSort);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(iMacRoomResourceConfigService.list(queryWrapper),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @GetMapping("/macroom/getMacRoomResourceDetail")
    public AjaxResult getMacRoomResourceDetail(String resourceId){
        return AjaxResult.data(iMacRoomResourceService.getById(resourceId));
    }

    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @GetMapping("/macroom/getMacRoomResourceList")
    public TableDataInfo getMacRoomResourceList(@RequestParam("macRoomId") String macRoomId,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("name")String name){
        QueryWrapper<MacRoomResourceView> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MacRoomResourceView::getDeleteFlag,0);
        queryWrapper.lambda().eq(MacRoomResourceView::getMacRoomId,macRoomId).orderByAsc(MacRoomResourceView::getResourceType).orderByAsc(MacRoomResourceView::getTitle);
        if(StringUtils.isNotBlank(name)){
            queryWrapper.lambda().like(MacRoomResourceView::getTitle,name);
        }
        return getDataTable(iMacRoomResourceViewService.page(new Page<>(pageNum,pageSize),queryWrapper));
    }

    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @GetMapping("/macroom/getMacRoomResourceListN")
    public AjaxResult getMacRoomResourceListN(@RequestParam("macRoomId") String macRoomId,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("name")String name){
        QueryWrapper<MacRoomResourceView> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(macRoomId)){
            queryWrapper.lambda().eq(MacRoomResourceView::getMacRoomId,macRoomId);
        }
        queryWrapper.lambda().orderByAsc(MacRoomResourceView::getResourceType).orderByAsc(MacRoomResourceView::getTitle);
        if(StringUtils.isNotBlank(name)){
            queryWrapper.lambda().like(MacRoomResourceView::getTitle,name);
        }
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(iMacRoomResourceViewService.page(new Page<>(pageNum,pageSize),queryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }


    /**
     * 根据机房名称查询机房信息
     * @return
d     */
    @GetMapping("/macroom/getMacRoomResourceListN1")
    public AjaxResult getMacRoomResourceListN1(@RequestParam("macRoomId") String macRoomId,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("name")String name,@RequestParam("resType")String restype,@RequestParam("buildId")String buildId,@RequestParam("deptId")String deptId,@RequestParam("qrCode")String qrCode){
        QueryWrapper<MacRoomResourceView> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(macRoomId)){
            queryWrapper.lambda().eq(MacRoomResourceView::getMacRoomId,macRoomId);
        }
        queryWrapper.lambda().orderByAsc(MacRoomResourceView::getResourceType).orderByAsc(MacRoomResourceView::getTitle);
        if(StringUtils.isNotBlank(name)){
            queryWrapper.lambda().like(MacRoomResourceView::getTitle,name);
        }
        if(StringUtils.isNotBlank(buildId)){
            queryWrapper.lambda().inSql(MacRoomResourceView::getMacRoomId,"select uuid from mac_room where build_id='"+buildId+"'");
        }
        if(StringUtils.isNotBlank(restype)){
            queryWrapper.lambda().eq(MacRoomResourceView::getResourceType,restype);
        }
        if(StringUtils.isNotBlank(deptId)){
            queryWrapper.lambda().eq(MacRoomResourceView::getZrDept,deptId);
        }
        if(StringUtils.isNotBlank(qrCode)){
            queryWrapper.lambda().eq(MacRoomResourceView::getCode,qrCode);
        }
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(iMacRoomResourceViewService.page(new Page<>(pageNum,pageSize),queryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }



    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @GetMapping("/selectMacRoomResourceData")
    public TableDataInfo selectMacRoomResourceData(MacRoomResource macRoomResource){
        return  iMacRoomResourceViewService.selectMacRoomResourceData(macRoomResource);
    }

    /**
     * 获取库房货架列表
     * @return
     */
    @GetMapping("/getStorageRackList")
    public AjaxResult getStorageRackList(@RequestParam("deptId") String deptId){
        QueryWrapper<StorageRack> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(deptId)){
            queryWrapper.lambda().eq(StorageRack::getDeptId,deptId);
        }
        queryWrapper.lambda().orderByAsc(StorageRack::getCode);
        return  AjaxResult.data(iStorageRackService.list(queryWrapper));
    }



    /**
     * 获取库房货架列表
     * @return
     */
    @GetMapping("/getStorageRackListN")
    public AjaxResult getStorageRackListN(@RequestParam("deptId") String deptId){
        QueryWrapper<StorageRack> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(deptId)){
            queryWrapper.lambda().eq(StorageRack::getDeptId,deptId);
        }
        queryWrapper.lambda().orderByAsc(StorageRack::getCode);
        return  AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(iStorageRackService.list(queryWrapper),"yyyy-MM-dd HH:mm:ss")));
    }

    /**
     * 机房申请验收
     * @return
     */
    @PostMapping("/order/sumbitWorkRecordBean")
    public AjaxResult sumbitWorkRecordBean(@RequestBody MacinoutAcceptResult acceptResult){
//        acceptResult.setCreateTime(DateUtil.now());
//        macinoutAcceptResultService.save(acceptResult);
//        MacinoutAssociation macinoutAssociation=new MacinoutAssociation();
//        macinoutAssociation.setUuid(acceptResult.getMacinoutAssId());
//        macinoutAssociation.setOrderStatus(5);
//        macinoutAssociationService.updateById(macinoutAssociation);
        return AjaxResult.ok();
    }


    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/updateEquCabinetNodesData")
    public AjaxResult updateEquCabinetNodesData(@RequestParam("data") String data){
        JSONArray objects = JSONUtil.parseArray(data);
        for(int i=0;i<objects.size();i++){
            JSONObject jsonObject = objects.getJSONObject(i);
            MacShow macShow=JSONUtil.toBean(jsonObject,MacShow.class);
            if(macShow.getCabinetId().startsWith("local")){
                EquCabinet equCabinet=new EquCabinet();
                equCabinet.setUuid(macShow.getCabinetId());
                EquCabinet cabinet = iEquCabinetService.getById(equCabinet);
                if(cabinet!=null){
                    equCabinet=cabinet;
                }
                equCabinet.setCabinetName(macShow.getCabinetName());
                equCabinet.setDeleteFlag(0);
                equCabinet.setEnergyName(macShow.getEqy());
                equCabinet.setMacId(macShow.getMacId());
                equCabinet.setUlocationQuantity(macShow.getUNum());
                if(cabinet!=null){
                    iEquCabinetService.updateById(equCabinet);
                }else{
                    iEquCabinetService.save(equCabinet);
                }

            }else{
                EquCabinet equCabinet=new EquCabinet();
                equCabinet.setUuid(macShow.getCabinetId());
                equCabinet.setCabinetName(macShow.getCabinetName());
                equCabinet.setDeleteFlag(0);
                equCabinet.setEnergyName(macShow.getEqy());
                equCabinet.setMacId(macShow.getMacId());
                equCabinet.setUlocationQuantity(macShow.getUNum());
                iEquCabinetService.updateById(equCabinet);
            }
            QueryWrapper<MacShow> queryWrapper=new QueryWrapper<>();
            queryWrapper.lambda().eq(MacShow::getMacId,macShow.getMacId()).eq(MacShow::getCabinetId,macShow.getCabinetId());
            List<MacShow> list = iMacShowService.list(queryWrapper);
            if(list.isEmpty()){
                iMacShowService.save(macShow);
            }else{
                MacShow macShow1 = list.get(0);
                macShow1.setNode(macShow.getNode());
                iMacShowService.updateById(macShow1);
            }
        }
        return AjaxResult.ok();
    }


    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/updateEquCabinetNodesDataN")
    public AjaxResult updateEquCabinetNodesDataN(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONArray objects = JSONUtil.parseArray(encode);
        for(int i=0;i<objects.size();i++){
            JSONObject jsonObject = objects.getJSONObject(i);
            MacShow macShow=JSONUtil.toBean(jsonObject,MacShow.class);
            if(macShow.getCabinetId().startsWith("local")){
                EquCabinet equCabinet=new EquCabinet();
                equCabinet.setUuid(macShow.getCabinetId());
                EquCabinet cabinet = iEquCabinetService.getById(equCabinet);
                if(cabinet!=null){
                    equCabinet=cabinet;
                }
                equCabinet.setCabinetName(macShow.getCabinetName());
                equCabinet.setDeleteFlag(macShow.getState());
                equCabinet.setEnergyName(macShow.getEqy());
                equCabinet.setMacId(macShow.getMacId());
                equCabinet.setUlocationQuantity(macShow.getUNum());
                if(cabinet!=null){
                    iEquCabinetService.updateById(equCabinet);
                }else{
                    iEquCabinetService.save(equCabinet);
                }

            }else{
                EquCabinet equCabinet=new EquCabinet();
                equCabinet.setUuid(macShow.getCabinetId());
                equCabinet.setCabinetName(macShow.getCabinetName());
                equCabinet.setDeleteFlag(macShow.getState());
                equCabinet.setEnergyName(macShow.getEqy());
                equCabinet.setMacId(macShow.getMacId());
                equCabinet.setUlocationQuantity(macShow.getUNum());
                iEquCabinetService.updateById(equCabinet);
            }
            QueryWrapper<MacShow> queryWrapper=new QueryWrapper<>();
            queryWrapper.lambda().eq(MacShow::getMacId,macShow.getMacId()).eq(MacShow::getCabinetId,macShow.getCabinetId());
            List<MacShow> list = iMacShowService.list(queryWrapper);
            if(list.isEmpty()){
                iMacShowService.save(macShow);
            }else{
                MacShow macShow1 = list.get(0);
                macShow1.setNode(macShow.getNode());
                iMacShowService.updateById(macShow1);
            }
        }
        return AjaxResult.ok();
    }

    @GetMapping("/plan/list")
    public AjaxResult appList(CheckPlan checkPlan) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        checkPlan.setRealUserId(user.getUserId() + "");
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(checkPlanService.selectPlanListByApp(checkPlan),"yyyy-MM-dd HH:mm:ss")));
    }


    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/saveOrUpdateEquCabinetData")
    public AjaxResult saveOrUpdateEquCabinetData(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        EquCabinet equCabinet1 = JSONUtil.toBean(parse, EquCabinet.class);
        if(StringUtils.isNotBlank(equCabinet1.getUuid())){
            equCabinet1.setUpdateTime(DateUtil.formatDateTime(new Date()));
            iEquCabinetService.updateById(equCabinet1);
        }else{
            equCabinet1.setUuid(UUID.randomUUID().toString());
            equCabinet1.setDeleteFlag(0);
            equCabinet1.setCreateTime(DateUtil.formatDateTime(new Date()));
            iEquCabinetService.save(equCabinet1);
        }
        return AjaxResult.ok();
    }

    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/saveOrUpdateRoomResourceData")
    public AjaxResult saveOrUpdateRoomResourceData(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        MacRoomResource macRoomResource = JSONUtil.toBean(parse, MacRoomResource.class);
        if(StringUtils.isNotBlank(macRoomResource.getUuid())){
            macRoomResource.setUpdateTime(DateUtil.formatDateTime(new Date()));
            iMacRoomResourceService.updateById(macRoomResource);
        }else{
            macRoomResource.setUuid(UUID.randomUUID().toString());
            macRoomResource.setDeleteFlag("0");
            macRoomResource.setCreateTime(DateUtil.formatDateTime(new Date()));
            iMacRoomResourceService.save(macRoomResource);
        }
        return AjaxResult.ok();
    }


    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/saveOrUpdateEquData")
    public AjaxResult saveOrUpdateEquData(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        EquipmentDetailDto equipmentDetailDto = JSONUtil.toBean(parse, EquipmentDetailDto.class);
        Equipment equipment1 = new Equipment();
        BeanUtils.copyProperties(equipmentDetailDto, equipment1);
        if(StringUtils.isNotBlank(equipmentDetailDto.getUuid())){
            equipmentMapper.updateById(equipment1);
            EquipmentDetail contrastEquipmentDetail = equipmentDetailMapper.selectByEquId(equipment1.getUuid());
            boolean isAdd = false;
            if (contrastEquipmentDetail == null) {
                contrastEquipmentDetail=new EquipmentDetail();
                contrastEquipmentDetail.setUuid(UUID.randomUUID().toString());
                isAdd = true;
            }
            copyEquipmentDetail(equipmentDetailDto, contrastEquipmentDetail);
            contrastEquipmentDetail.setEquId(equipment1.getUuid());
            //核验设备数据并插入
            if (isAdd) {
                equipmentDetailMapper.insert(contrastEquipmentDetail);
            } else {
                equipmentDetailMapper.updateById(contrastEquipmentDetail);
            }
        }else{
            equipment1.setDeleteFlag(0);
            equipment1.setCreateTime(DateUtil.now());
            equipment1.setUuid(UUID.randomUUID().toString());
            equipmentMapper.insert(equipment1);
            EquipmentDetail contrastEquipmentDetail = new EquipmentDetail();
            copyEquipmentDetail(equipmentDetailDto, contrastEquipmentDetail);
            contrastEquipmentDetail.setUuid(equipment1.getUuid());
            contrastEquipmentDetail.setEquId(equipment1.getUuid());
            //核验设备数据并插入
            equipmentDetailMapper.insert(contrastEquipmentDetail);
        }
        return AjaxResult.ok();
    }


    private void copyEquipmentDetail(EquipmentDetailDto equipmentDetailDto, EquipmentDetail contrastEquipmentDetail) {
        contrastEquipmentDetail.setAssetsBigType(equipmentDetailDto.getAssetsBigType());
        contrastEquipmentDetail.setAssetsSmallType(equipmentDetailDto.getAssetsSmallType());
        contrastEquipmentDetail.setAssetsNumber(equipmentDetailDto.getAssetsNumber());
        contrastEquipmentDetail.setOwnerSystem(equipmentDetailDto.getOwnerSystem());
        contrastEquipmentDetail.setModelType(equipmentDetailDto.getModelType());
        contrastEquipmentDetail.setAssetsState(equipmentDetailDto.getAssetsState());
        contrastEquipmentDetail.setPrincipal(equipmentDetailDto.getPrincipal());
        contrastEquipmentDetail.setDepartment(equipmentDetailDto.getDepartment());
        contrastEquipmentDetail.setOffice(equipmentDetailDto.getOffice());
        contrastEquipmentDetail.setMacRoomName(equipmentDetailDto.getMacRoomName());
        contrastEquipmentDetail.setCabinetId(equipmentDetailDto.getCabinetId());
        contrastEquipmentDetail.setOpenDate(equipmentDetailDto.getOpenDate());
        contrastEquipmentDetail.setUfloorNum(equipmentDetailDto.getUfloorNum());
        contrastEquipmentDetail.setCabinetName(equipmentDetailDto.getCabinetName());
        contrastEquipmentDetail.setEquId(equipmentDetailDto.getEquId());
        contrastEquipmentDetail.setEquName(equipmentDetailDto.getEquName());
        contrastEquipmentDetail.setEquHeight(equipmentDetailDto.getEquHeight());
        contrastEquipmentDetail.setUpdateTime(DateUtil.now());
        contrastEquipmentDetail.setCreateTime(DateUtil.now());
    }


    @GetMapping("/macroom/getMacBuildResourceList")
    public AjaxResult getMacBuildResourceList(@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("name") String name,@RequestParam("parkId") String parkId){
        LambdaQueryWrapper<MacBuild> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MacBuild::getState,"0");
        if(StringUtils.isNotBlank(name)){
            lambdaQueryWrapper.like(MacBuild::getName,name);
        }
        if(StringUtils.isNotBlank(parkId)){
            lambdaQueryWrapper.eq(MacBuild::getIndustrialId,parkId);
        }
        lambdaQueryWrapper.orderByAsc(MacBuild::getName);
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(macBuildMapper.selectPage(new Page<>(pageNum,pageSize),lambdaQueryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }


    @GetMapping("/macroom/getCheckPlanByDept")
    public AjaxResult getCheckPlanByDept(@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("dept") String dept){
        LambdaQueryWrapper<CheckPlan> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(dept)){
            lambdaQueryWrapper.eq(CheckPlan::getUserId,dept).orderByDesc(CheckPlan::getCreateTime);
        }
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(checkPlanService.page(new Page<>(pageNum,pageSize),lambdaQueryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }



    /**
     * 根据机房名称查询机房信息
     * @return
     */
    @PostMapping("/macroom/addCheckPlan")
    public AjaxResult addCheckPlan(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        CheckPlan checkPlan = JSONUtil.toBean(parse, CheckPlan.class);
        checkPlan.setUuid(UUID.randomUUID().toString());
        checkPlan.setCreateTime(DateUtil.now());
        checkPlanService.addPlan(checkPlan);
        return AjaxResult.ok();
    }

    @PostMapping("/macroom/addPark")
    public AjaxResult addPark(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        MacIndustrial macIndustrial = JSONUtil.toBean(parse, MacIndustrial.class);
        if(StringUtils.isBlank(macIndustrial.getId())){
            macIndustrial.setId(UUID.randomUUID().toString());
            macIndustrial.setCreatetime(new Date());
            macIndustrial.setState("0");
            macIndustrialMapper.insert(macIndustrial);
        }else{
            macIndustrialMapper.updateById(macIndustrial);
        }
        return AjaxResult.ok();
    }


    @GetMapping("/macroom/getParkByName")
    public AjaxResult getParkByName(@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum,@RequestParam("name") String name){
        LambdaQueryWrapper<MacIndustrial> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MacIndustrial::getState,"0");
        if(StringUtils.isNotBlank(name)){
            lambdaQueryWrapper.like(MacIndustrial::getName,name).orderByAsc(MacIndustrial::getName);
        }
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(getDataTable(macIndustrialMapper.selectPage(new Page<>(pageNum,pageSize),lambdaQueryWrapper)),"yyyy-MM-dd HH:mm:ss")));
    }


    @PostMapping("/macroom/addBuild")
    public AjaxResult addBuild(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        MacBuild macIndustrial = JSONUtil.toBean(parse, MacBuild.class);
        if(StringUtils.isBlank(macIndustrial.getId())) {
            macIndustrial.setId(UUID.randomUUID().toString());
            macIndustrial.setCreatetime(new Date());
            macIndustrial.setState("0");
            macBuildMapper.insert(macIndustrial);
        }else{
            macBuildMapper.updateById(macIndustrial);
        }
        return AjaxResult.ok();
    }

    @PostMapping("/macroom/addRoom")
    public AjaxResult addRoom(@RequestBody AesRequestBean aesRequestBean){
        String encode = AESUtils.decode(aesRequestBean.getData());
        JSONObject parse = JSONUtil.parseObj(encode);
        MacRoom macIndustrial = JSONUtil.toBean(parse, MacRoom.class);
        if(StringUtils.isBlank(macIndustrial.getUuid())) {
            macIndustrial.setCreateTime(DateUtil.now());
            macIndustrial.setUuid(UUID.randomUUID().toString());
            macIndustrial.setDelteFlag(0);
            macRoomService.save(macIndustrial);
        }else{
            macRoomService.saveOrUpdate(macIndustrial);
        }
        return AjaxResult.ok();
    }


    @GetMapping("/macroom/deleteMacResoureData")
    public AjaxResult getParkByName(@RequestParam("id") String id){
        iEquCabinetService.removeById(id);
        iMacRoomResourceService.removeById(id);
        return AjaxResult.ok();
    }



    @GetMapping("/powerOrder/validate")
    public AjaxResult powerValidate(@RequestParam("name") String name) {
        String nickname = name;
        LambdaQueryWrapper<PowerOrderRoom> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.inSql(PowerOrderRoom::getMacRoomId,"select uuid from mac_room where update_by='"+nickname+"'").eq(PowerOrderRoom::getState,"0");
        Integer integer = powerOrderRoomMapper.selectCount(lambdaQueryWrapper);
        return AjaxResult.data(integer);
    }


    @GetMapping("/powerOrder/getPowerOrder")
    public AjaxResult getPowerOrder(@RequestParam("name") String name,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum) {
        String nickname = name;
        LambdaQueryWrapper<PowerOrder> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.inSql(PowerOrder::getId,"select mac_power_order_id from mac_power_order_rooms where mac_room_id in  (select uuid from mac_room where update_by='"+nickname+"') and state='0'").orderByDesc(PowerOrder::getCreateTime);
        TableDataInfo dataTable = getDataTable(powerOrderMapper.selectPage(new Page<>(pageNum, pageSize), lambdaQueryWrapper));
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(dataTable,"yyyy-MM-dd HH:mm:ss")));
    }

    @GetMapping("/powerOrder/getPowerRoom")
    public AjaxResult getPowerRoom(@RequestParam("orderid") String orderid,@RequestParam("name") String name,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum) {
        LambdaQueryWrapper<PowerOrderRoom> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.inSql(PowerOrderRoom::getMacRoomId,"select uuid from mac_room where update_by='"+name+"'").eq(PowerOrderRoom::getMacPowerOrderId,orderid).orderByAsc(PowerOrderRoom::getState);
        TableDataInfo dataTable = getDataTable(powerOrderRoomMapper.selectPage(new Page<>(pageNum, pageSize), lambdaQueryWrapper));
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(dataTable,"yyyy-MM-dd HH:mm:ss")));
    }
    @GetMapping("/powerOrder/getPowerRock")
    public AjaxResult getPowerRock(@RequestParam("orderid") String orderid,@RequestParam("name") String name,@RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum) {
        LambdaQueryWrapper<PowerOrderRack> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(PowerOrderRack::getMacRackName,name).eq(PowerOrderRack::getMacPowerOrderId,orderid).orderByAsc(PowerOrderRack::getMacRackName);
        TableDataInfo dataTable = getDataTable(powerOrderRackMapper.selectPage(new Page<>(pageNum, pageSize), lambdaQueryWrapper));
        return AjaxResult.data(AESUtils.encode(JSON.toJSONStringWithDateFormat(dataTable,"yyyy-MM-dd HH:mm:ss")));
    }

    @GetMapping("/powerOrder/updatePowerRoom")
    public AjaxResult updatePowerRoom(@RequestParam("id") String id,@RequestParam("name") String name) {
        PowerOrderRoom powerOrderRoom = powerOrderRoomMapper.selectById(id);
        powerOrderRoom.setState("1");
        powerOrderRoom.setUpdateBy(name);
        powerOrderRoom.setUpdateTime(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
        powerOrderRoomMapper.updateById(powerOrderRoom);
        return AjaxResult.ok();
    }

}
